using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Metropolicity
{
    class EnergyCell : InteractableGameObject
    {
        public Vector2 velocity;
        public int power;
        public int energySpeed;
        public Texture2D testPixels;
        public EnergyCell(String texturePath, Vector2 location)
            : base(texturePath, location)
        {
            velocity = new Vector2();
            zindex = 1f;
        }
        public override void Update(GameTime gameTime)
        {
            if (velocity != new Vector2())
                velocity.Normalize();
            position += velocity*energySpeed;
            if (position.X >= 800*scale || position.X <=0)
                velocity.X *= -1;
            if (position.Y >= 480*scale || position.Y<=0)
                velocity.Y *= -1;
            base.Update(gameTime);
        }
        public override void LoadContent(ContentManager content)
        {
            testPixels= content.Load<Texture2D>("testPixel");
            if (texturePath != null)
            {
                    this.texture = content.Load<Texture2D>(texturePath);
                    this.rectangle = new Rectangle(
                        (int)position.X,
                        (int)position.Y,
                        (int)(texture.Width*scale),
                        (int)(texture.Height*scale)
                        );
            }
        }
        public void givePower(int requiredPower)
        {
            power -= requiredPower;
        }
        public override void Draw(SpriteBatch spriteBatch)
        {
            if (this.visible)
            {
                if (this.texture != null)
                {
                    spriteBatch.Draw(testPixels, position, Color.Red);
                    spriteBatch.Draw(testPixels, rectangle, Color.Blue);
                    spriteBatch.Draw(this.texture, this.position, null, this.tintColor, this.rotation, new Vector2(texture.Width / 2, texture.Height / 2), scale, SpriteEffects.None, this.zindex);
                }
            }
        }
    }
}
